package com.cdatos.golGana.providers;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

public class SortableGenericsDataProvider<T extends Serializable> extends SortableDataProvider<T> {
	private static final long serialVersionUID = 1L;
	private List<T> items;
	
	public SortableGenericsDataProvider(List<T> items, String sortField, boolean ascending) {
		setSort(sortField, ascending);
		this.items = items;
	}

	public Iterator<? extends T> iterator(int first, int count) {
		return items.subList(first, first + count).iterator();
	}

	public IModel<T> model(final T object) {
		return new Model<T>(object);
	}

	public int size() {
		return items.size();
	}
	
}
